import { Component, OnInit, Injector } from '@angular/core';
import { switchMap } from '../../../../../node_modules/rxjs/operators';
import { ParamMap, ActivatedRoute } from '../../../../../node_modules/@angular/router';
import { HttpService } from '../../..';
import { NgZorroPageBaseComponent } from '../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { BaseComponentConfig } from '../../../core/model/BaseComponentConfig';
import { ArSystemFormControl, SystemFormControl, FieldType, LoadRemoteDataType, ExpressionPair, Compare, AndOr } from '../../../core/model/CommonDto';

@Component({
  selector: 'app-student-score-list',
  templateUrl: './student-score-list.component.html',
  styleUrls: ['./student-score-list.component.scss']
})
export class StudentScoreListComponent extends NgZorroPageBaseComponent implements OnInit {
  selectProjectId;
  lstSubject = [];
  selectSubjectId;
  lstClass = [];
  selectClassId;
  searchText = "";
  constructor(
    private inject: Injector,
  ) {
    super(
      inject,
      new BaseComponentConfig('teacherinfo/TeacherStudentScores', '', '', '', '', 'id', '', '学生成绩', null, null),
      new ArSystemFormControl(new Array<SystemFormControl>(
        new SystemFormControl("personName", "姓名", FieldType.Text, true, 30, 0, "", "", false, null, null),
        new SystemFormControl("className", "班级", FieldType.Text, true, 30, 0, "", "", false, null, null),
        new SystemFormControl("subjectName", "课程", FieldType.Text, true, 30, 0, "", "", false, null, null),
        new SystemFormControl("drillScore", "演练分", FieldType.Text, true, 30, 0, "", "", false, null, null),
        new SystemFormControl("groupDrillScore", "教师评分", FieldType.Text, true, 30, 0, "", "", false, null, null),
        new SystemFormControl("reportScore", "报告分", FieldType.Text, true, 30, 0, "", "", false, null, null),
        new SystemFormControl("totalScore", "总分", FieldType.Text, false, 300, 0, "", "", false, null, null),
      )));
  }

  ngOnInit() {
    const $this = this;
    this.route.paramMap.pipe(
      switchMap((params: ParamMap) => {
        this.selectProjectId = +params.get('id');
        $this.IniObserver.subscribe(e => {
          this.search();
        });
        return this.getSubject();
      })
    ).subscribe();

  }

  /**
   * 获取主体列表
   */
  async getSubject() {
    if (this.selectProjectId) {
      this.lstSubject = await this.httpService.get<any>(`teacherinfo/TeacherProjectSubjects?projectid=${this.selectProjectId}`);
    }

  }

  /**
   * 根据主题获取班级列表
   * @param subjectId 主题id
   */
  async getClass(subjectId: number) {
    this.lstClass = [];
    if (subjectId) {
      this.lstClass = await this.httpService.get<any>(`teacherinfo/TeacherSubejectClasses?subjectid=${subjectId}`);
    }
  }

  async search() {
    this.listSearchValue = new Array<ExpressionPair>(
      new ExpressionPair('projectid', this.selectProjectId, Compare.Equal, AndOr.And),
      new ExpressionPair('subjectid', this.selectSubjectId, Compare.Equal, AndOr.And),
      new ExpressionPair('classid', this.selectClassId, Compare.Equal, AndOr.And),
      new ExpressionPair('username', this.searchText, Compare.Equal, AndOr.And),
    );
    this.getEntityList();
  }
}
